#include <iostream>
#include <curses.h>
#include <ctime>
#include "map.h"
#include "object.h"
#include "double-linked-list.h"
#include "random.h"
#include "window.h"

using namespace std;

#define STARTX 5
#define STARTY 11
#define STARTZ 0
/*
void display(Creature *p, Map *m)
{
	m->refresh();
	m->set(p->x(),p->y(),p->symbol());
	for (int i=0; i<m->height(); i++)
	{
		for (int j=0; j<m->width(); j++)
			mvaddch(i, j, m->isAt(j, i));
	}
	mvprintw(m->height(), 0, "Name:\t\tElzair");
	mvprintw(m->height()+1, 0, "Location:\t%d %d", p->x(), p->y());
	mvprintw(m->height()+2, 0, "Hitpoints:\t%d/%d", p->currentHitpoints(), p->maximumHitpoints());
	mvprintw(m->height()+3, 0, "Energy:\t\t%d/%d", p->currentEnergy(), p->maximumEnergy());
	mvprintw(m->height()+4, 0, "Strength:\t%d/%d", p->currentStrength(), p->maximumStrength());
	mvprintw(m->height()+5, 0, "Dexterity:\t%d/%d", p->currentDexterity(), p->maximumDexterity());
	mvprintw(m->height()+6, 0, "Constitution:\t%d/%d", p->currentConstitution(), p->maximumConstitution());
	refresh(); 
}
*/

int main(int argc, char **argv)
{
	cerr << "Hello world!" << endl;
	string filename;
	if (argc == 2)
		filename = argv[1];
	else
		filename = "test.map";
	cerr << filename << endl;

	Creature *p = new Creature("Player", '@', STARTX, STARTY, STARTZ, true, 100, 100, 10, 10, 10, 100, 100, 10, 10, 10);
	
	// Initialize terrain types
	Double_Linked_List *terrain = new Double_Linked_List();
	Mersenne_Twister *mt = new Mersenne_Twister(time(NULL));
	Map *m = new Map(mt, filename);
	m->add(STARTX, STARTY, p);
	Curses_Window *window = new Curses_Window(m);
	
	while(!window->quitGame())
	{
		window->display(p);
		window->processInput(p);
	}
	
	delete m;
	delete p;
	delete terrain;
	delete mt;
	delete window;
	return 0;
}
/*
int main(int argc, char **argv)
{
	
	int end = false;
	int input;

	Map *m = new Map("test.map");
	Creature *p = new Creature("Player", '@', STARTX, STARTY, STARTZ, true, 100, 100, 10, 10, 10, 100, 100, 10, 10, 10);
	Double_Linked_List *l = new Double_Linked_List();
	Mersenne_Twister *mt = new Mersenne_Twister(time(NULL));
	
	
	initscr();
	keypad(stdscr, true);
	nonl();
	cbreak();
	noecho();
	
	while (!end)
	{
		display(p, m);
		input = getch();
		int x = p->x();
		int y = p->y();
		switch(input)
		{
			case 'h':
				if (m->isAt(x-1,y) != '#')
					p->move(x-1,y,0);
				break;
			case 'j':
				if (m->isAt(x,y+1) != '#')
					p->move(x,y+1,0);
				break;
			case 'k':
				if (m->isAt(x,y-1) != '#')
					p->move(x,y-1,0);
				break;
			case 'l':
				if (m->isAt(x+1,y) != '#')
					p->move(x+1,y,0);
				break;
			case 'y':
				if (m->isAt(x-1,y-1) != '#')
					p->move(x-1,y-1,0);
				break;
			case 'u':
				if (m->isAt(x+1,y-1) != '#')
					p->move(x+1,y-1,0);
				break;
			case 'b':
				if (m->isAt(x-1,y+1) != '#')
					p->move(x-1,y+1,0);
				break;
			case 'n':
				if (m->isAt(x+1,y+1) != '#')
					p->move(x+1,y+1,0);
				break;
			case 'q':
				end = true;
				break;
			case '4':
				if (m->isAt(x-1,y) != '#')
					p->move(x-1,y,0);
				break;
			case '2':
				if (m->isAt(x,y+1) != '#')
					p->move(x,y+1,0);
				break;
			case '8':
				if (m->isAt(x,y-1) != '#')
					p->move(x,y-1,0);
				break;
			case '6':
				if (m->isAt(x+1,y) != '#')
					p->move(x+1,y,0);
				break;
			case '7':
				if (m->isAt(x-1,y-1) != '#')
					p->move(x-1,y-1,0);
				break;
			case '9':
				if (m->isAt(x+1,y-1) != '#')
					p->move(x+1,y-1,0);
				break;
			case '1':
				if (m->isAt(x-1,y+1) != '#')
					p->move(x-1,y+1,0);
				break;
			case '3':
				if (m->isAt(x+1,y+1) != '#')
					p->move(x+1,y+1,0);
				break;
			case KEY_LEFT:
				if (m->isAt(x-1,y) != '#')
					p->move(x-1,y,0);
				break;
			case KEY_DOWN:
				if (m->isAt(x,y+1) != '#')
					p->move(x,y+1,0);
				break;
			case KEY_UP:
				if (m->isAt(x,y-1) != '#')
					p->move(x,y-1,0);
				break;
			case KEY_RIGHT:
				if (m->isAt(x+1,y) != '#')
					p->move(x+1,y,0);
				break;
			case KEY_HOME:
				if (m->isAt(x-1,y-1) != '#')
					p->move(x-1,y-1,0);
				break;
			case KEY_PPAGE:
				if (m->isAt(x+1,y-1) != '#')
					p->move(x+1,y-1,0);
				break;
			case KEY_END:
				if (m->isAt(x-1,y+1) != '#')
					p->move(x-1,y+1,0);
				break;
			case KEY_NPAGE:
				if (m->isAt(x+1,y+1) != '#')
					p->move(x+1,y+1,0);
				break;
			default:
				break;
		}
	}
	endwin();
	return 0;
}
*/
